package me.winter.imgop;

// Lossless Algorithm

// This class involves computing the difference between pixel values.
// First, leave the pixels along the topmost row of image unchanged.
// Then, replace every other value in each pixel array with the difference
// between its origin value and the original value of the pixel directly
// above it.

public class WaterfallSimplifier extends ImageSimplifier
{
    public WaterfallSimplifier()
    {

    }

    @Override
	public int [][] encodePixels( int [][] shades ) {
        for (int x = 0; x < shades.length; ++x) {
            int theAbove = shades[x][0];

            for (int y = 1; y < shades[0].length; ++y) {
                int temp = shades[x][y];
                shades[x][y] = shades[x][y] - theAbove;
                theAbove = temp;
            }
        }
        return shades;
    }

    @Override
	public int [][] decodePixels( int [][] shades ) {
        for (int x = 0; x < shades.length; ++x) {
            for (int y = 1; y < shades[0].length; ++y) {
                shades[x][y] = shades[x][y] + shades[x][y - 1];
            }
        }

        return shades;
    }
}
